// 删除排序链表中的重复元素

package Leetcode;

// import java.util.List;

/**
 * Definition for singly-linked list.
 * public class ListNode {
 * int val;
 * ListNode next;
 * ListNode() {}
 * ListNode(int val) { this.val = val; }
 * ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class solution_083 {
    public ListNode deleteDuplicates(ListNode head) {
        ListNode pre = new ListNode();
        ListNode slow = new ListNode();
        ListNode fast = new ListNode();
        pre.next = head;
        slow = head;
        // 只有一个结点
        if (head == null || head.next == null)
            return pre.next;
        fast = head.next;
        while (fast != null) {
            if (fast.val != slow.val) {
                slow.next = fast;
                slow = slow.next;
            }
            fast = fast.next;
            // 当fast为null则需要赋值否则slow最终没指向null
            if (fast == null)
                slow.next = fast;
        }
        return pre.next;
    }
}

public class Solution083 {

}
